//
// Created by Administrator on 2021/01/04 004.
//
#include <InnerThreadDemo.h>

#include "include/InnerThreadDemo.h"

void InnerThreadDemo::stepIt(const int& step) {
    cout<<"thread id = " << std::this_thread::get_id()<<endl<<num<<endl;
}

void InnerThreadDemo::minusStep() {

    std::lock_guard<std::mutex> lock(mtx);
    num--;
    cout<<"num = "<<num<<endl;
}

void InnerThreadDemo::startCalc() {
    //创建thread可以使用以下方式
//    std::thread t = thread(&InnerThreadDemo::stepIt, this, 100);
//    std::thread t = thread(std::bind(&InnerThreadDemo::stepIt, _1, _2), this, 100);
//    std::thread t = thread(std::bind(&InnerLogic::stepIt, this, 100));
//    std::thread t = thread(std::mem_fn(&InnerLogic::stepIt), this, 100);
//    t.join();


    for (int i = 0; i < 5; ++i) {
        auto t = thread(&InnerThreadDemo::minusStep, this);
        t.detach();
    }
}

